package baoliDigui;

//汉诺塔问题
public class HanNo {
    public static void main(String[] args) {
        leftToRight(3);
        System.out.println("--------------");
        funC(3,"左","中" ,"右");
    }

    //使用一个方法解决
    public static void funC(int n,String from,String other,String to){
        if (n==1){
            System.out.println(from+" ->  "+to);
        }else {
            funC(n-1,from,to,other);
            System.out.println(from+" ->  "+to);
            funC(n-1,other,from,to);
        }
    }



    public static void leftToRight(int n){
        if (n==1){
            System.out.println("左 ->  右");
        }else {
            leftToMid(n-1);
            System.out.println("左 ->  右");
            midToRight(n-1);
        }
    }

    public static void leftToMid(int n){
        if (n==1){
            System.out.println("左 ->  中");
        }else {
            leftToRight(n-1);
            System.out.println("左 ->  中");
            rightToMid(n-1);
        }
    }

    public static void midToRight(int n){
        if (n==1){
            System.out.println("中 ->  右");
        }else {
            midToLeft(n-1);
            System.out.println("中 ->  右");
            leftToRight(n-1);
        }
    }

    public static void midToLeft(int n){
        if (n==1){
            System.out.println("中 ->  左");
        }else {
            midToRight(n-1);
            System.out.println("中 ->  左");
            rightToLeft(n-1);
        }
    }

    public static void rightToMid(int n){
        if (n==1){
            System.out.println("右 ->  中");
        }else {
            rightToLeft(n-1);
            System.out.println("右 ->  中");
            leftToMid(n-1);
        }
    }

    public static void rightToLeft(int n){
        if (n==1){
            System.out.println("右 ->  左");
        }else {
            rightToMid(n-1);
            System.out.println("右 ->  左");
            midToLeft(n-1);
        }
    }
}
